<!--
描述：填空题审核-批量审核组件
开发人：zyanming
开发日期：2019年10月17日
-->
<template lang="pug">
    kalix-dialog.user-add(bizKey="completionCheck" ref="kalixBizDialog" v-bind:formModel.sync="formModel"
    v-bind:submitCustom="submitCustom")
        div.el-form(slot="dialogFormSlot")
            el-form-item.s-flex_item(label="审核不通过原因" prop="reason" v-bind:label-width="labelWidth")
                el-input(v-model="formModel.reason" type="textarea")
</template>

<script type="text/ecmascript-6">
    import FormModel from '../../questioninput/completion/model'
    import {CompletionCheckURL} from '../../config.toml'

    export default {
        name: 'CompletionCheckAudit',
        data() {
            return {
                formModel: Object.assign({}, FormModel),
                targetURL: CompletionCheckURL,
                labelWidth: '120px'
            }
        },
        methods: {
            submitCustom(baseDialog) {
                baseDialog.$refs.dialogForm.validate((valid) => {
                    if (valid) {
                        this.$http.request({
                            method: 'PUT',
                            url: this.targetURL,
                            data: {},
                            params: {
                                entityIds: this.formModel.id.toString(),
                                checkFlag: '2',
                                reason: this.formModel.reason
                            }
                        }).then(response => {
                            if (response.data.success) {
                                this.$KalixMessage.success(response.data.msg)
                                this.visible = false
                                baseDialog.$refs.dialogForm.resetFields()
                                baseDialog.submitComplete()
                            } else {
                                this.$KalixMessage.error(response.data.msg)
                                baseDialog.submitComplete()
                            }
                            // 刷新列表
                            this.$KalixEventBus.$emit(this.$KalixEventConfig.ON_REFRESH_DATA)
                            baseDialog._afterDialogClose()
                            console.log('[kalix] dialog submit button clicked !')
                            baseDialog.visible = false
                        })
                    } else {
                        this.$KalixMessage.error('请检查输入项！')
                        baseDialog.submitComplete(false)
                        return false
                    }
                })
            }
        }
    }
</script>
